home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 23 / AACD 23.iso / AACD / Programming / tek / mem.h < prev    next >
C/C++ Source or Header  |  2001-05-26  |  7KB  |  154 lines

  1.  
  2. #ifndef _TEK_MEM_H
  3. #define _TEK_MEM_H 1
  4.  
  5. /*
  6. **    tek/mem.h
  7. **
  8. */
  9.  
  10. #include <tek/list.h>
  11. #include <tek/util.h>
  12.  
  13.  
  14. typedef TINT (*TDESTROYFUNC)(TAPTR handle);
  15.  
  16.  
  17. typedef struct                    /* generic object handle */
  18. {
  19.     TNODE node;                    /* node header for linkage */
  20.     TAPTR mmu;                    /* memory management unit */
  21.     TDESTROYFUNC destroyfunc;    /* destroy function for this object */
  22. }    THNDL;
  23.  
  24.  
  25. typedef struct                    /* lowlevel memheader. consider it private */
  26. {
  27.     THNDL handle;                /* object handle (currently needed for linking to a MMU) */
  28.     TBYTE *mem;                    /* ptr to raw memory */
  29.     TUINT memnodesize;            /* size of a memory node, including alignment */
  30.     TUINT align;                /* alignment size - 1 [bytes] */
  31.     TUINT freesize;                /* total number of free bytes in this block */
  32. }    TMEMHEAD;
  33.  
  34.  
  35. typedef struct _tmemnode        /* lowlevel memnode. may be considered private */
  36. {
  37.     struct _tmemnode *next;
  38.     struct _tmemnode *prev;
  39.     TUINT free;                    /* number of bytes free in this node */
  40.     TUINT size;                    /* number of bytes handled by this node */
  41. }    TMEMNODE;
  42.  
  43.  
  44. typedef struct                    /* mempool. private. */
  45. {
  46.     THNDL handle;    
  47.     TLIST list;                    /* list of static pools */
  48.     TUINT align;                /* memory alignment size */
  49.     TUINT chunksize;            /* aligned size of chunk allocations */
  50.     TUINT thressize;            /* aligned threshold for regular-block allocations */
  51.     TUINT poolnodesize;            /* aligned size of poolheader */
  52.     TUINT memnodesize;            /* aligned size of a memnode */
  53.     TBOOL dyngrow;                /* perform dynamic pool growth */
  54.     TFLOAT dynfactor;            /* chunk/thressize. adapted before allocating large chunks. */
  55. }    TMEMPOOL;
  56.  
  57.  
  58. typedef struct                    /* mempool node. private. */
  59. {
  60.     TNODE node;
  61.     TMEMHEAD memhead;
  62.     TUINT numbytes;                /* actually allocatable size */
  63. }    TPOOLNODE;
  64.  
  65.  
  66. typedef struct                                    /* memory management unit */
  67. {
  68.     THNDL handle;                                /* object handle */
  69.     TUINT type;                                    /* type of this MMU */
  70.     TAPTR allocator;                            /* primary allocator, may be backptr to this MMU */
  71.     TAPTR suballocator;                            /* sub allocator, can be destroyed with destroymmufunc */
  72.     TDESTROYFUNC destroyallocatorfunc;            /* function to destroy allocator or suballocator */
  73.     TDESTROYFUNC destroymmufunc;                /* function to destroy MMU, or TNULL */
  74.  
  75.     TAPTR (*allocfunc)(TAPTR allocator, TUINT size);                        /* callback hub functions */
  76.     TVOID (*freefunc)(TAPTR allocator, TAPTR mem);
  77.     TAPTR (*reallocfunc)(TAPTR allocator, TAPTR mem, TUINT newsize);
  78.     TUINT (*getsizefunc)(TAPTR allocator, TAPTR mem);
  79.     TAPTR reserved[2];
  80.  
  81.     TLIST tracklist;                            /* tracking list for allocations */
  82.     TKNOB tasklock;                                /* lock for multitasking access */
  83.     TAPTR userdata;                                /* unrestricted use for user MMUs */
  84.  
  85. }    TMMU;
  86.  
  87.  
  88. /* 
  89. **    mmu types.
  90. */
  91.  
  92. #define TMMUT_Void        0x00000000        /* void MMU incapable of allocating */
  93. #define TMMUT_MMU        0x00000100        /* put MMU on top of a parent MMU */
  94. #define TMMUT_Kernel    0x00000101        /* put MMU on top of kernel */
  95. #define TMMUT_Static    0x00000102        /* put MMU on top of a static memheader */
  96. #define TMMUT_Pooled    0x00000103        /* put MMU on top of a pooled allocator */
  97. #define TMMUT_Tracking    0x00001000        /* implement memory tracking on top of a parent MMU */
  98. #define TMMUT_TaskSafe    0x00002000        /* implement task-safety on top of a parent MMU */
  99. #define TMMUT_Message    0x00010000        /* message allocator on top of a parent (or TNULL) MMU */
  100.  
  101.  
  102. /* 
  103. **    mem tags.
  104. */
  105.  
  106. #define TMEMTAGS_                    (TTAG_USER + 0x200)
  107. #define TMem_DynGrow                (TTAG) (TMEMTAGS_ + 0)        /* use dynamic pool growth */
  108.  
  109.  
  110.  
  111. TBEGIN_C_API
  112.  
  113.  
  114. extern TVOID TMemCopy(TAPTR from, TAPTR to, TUINT numbytes)                                __ELATE_QCALL__(("qcall lib/tek/mem/memcopy"));
  115. extern TVOID TMemCopy32(TAPTR from, TAPTR to, TUINT numbytes)                            __ELATE_QCALL__(("qcall lib/tek/mem/memcopy32"));
  116. extern TVOID TMemFill(TAPTR dest, TUINT numbytes, TUINT fillval)                        __ELATE_QCALL__(("qcall lib/tek/mem/memfill"));
  117. extern TVOID TMemFill32(TAPTR dest, TUINT numbytes, TUINT fillval)                        __ELATE_QCALL__(("qcall lib/tek/mem/memfill32"));
  118.  
  119. extern TBOOL TInitMemHead(TMEMHEAD *head, TAPTR mem, TUINT size, TTAGITEM *tags)        __ELATE_QCALL__(("qcall lib/tek/mem/initmemhead"));
  120. extern TAPTR TStaticAlloc(TMEMHEAD *head, TUINT size)                                    __ELATE_QCALL__(("qcall lib/tek/mem/staticalloc"));
  121. extern TVOID TStaticFree(TMEMHEAD *head, TAPTR mem)                                        __ELATE_QCALL__(("qcall lib/tek/mem/staticfree"));
  122. extern TAPTR TStaticRealloc(TMEMHEAD *head, TAPTR mem, TUINT size)                        __ELATE_QCALL__(("qcall lib/tek/mem/staticrealloc"));
  123. extern TUINT TStaticGetSize(TMEMHEAD *head, TAPTR mem)                                    __ELATE_QCALL__(("qcall lib/tek/mem/staticgetsize"));
  124.  
  125. extern TAPTR TCreatePool(TAPTR mmu, TUINT chunksize, TUINT thressize, TTAGITEM *tags)    __ELATE_QCALL__(("qcall lib/tek/mem/createpool"));
  126. extern TAPTR TPoolAlloc(TAPTR pool, TUINT size)                                            __ELATE_QCALL__(("qcall lib/tek/mem/poolalloc"));
  127. extern TVOID TPoolFree(TAPTR pool, TAPTR mem)                                            __ELATE_QCALL__(("qcall lib/tek/mem/poolfree"));
  128. extern TAPTR TPoolRealloc(TAPTR pool, TAPTR mem, TUINT size)                            __ELATE_QCALL__(("qcall lib/tek/mem/poolrealloc"));
  129. extern TUINT TPoolGetSize(TAPTR mp, TAPTR mem)                                            __ELATE_QCALL__(("qcall lib/tek/mem/poolgetsize"));
  130.  
  131. extern TBOOL TInitMMU(TMMU *mmu, TAPTR allocator, TUINT mmutype, TTAGITEM *tags)        __ELATE_QCALL__(("qcall lib/tek/mem/initmmu"));
  132. extern TAPTR TMMUAlloc0(TAPTR mmu, TUINT size)                                            __ELATE_QCALL__(("qcall lib/tek/mem/mmualloc0"));
  133. extern TAPTR TMMURealloc(TAPTR mmu, TAPTR mem, TUINT newsize)                            __ELATE_QCALL__(("qcall lib/tek/mem/mmurealloc"));
  134.  
  135. extern TAPTR TMMUAlloc(TAPTR mmu, TUINT size)                                            __ELATE_QCALL__(("qcall lib/tek/mem/mmualloc"));
  136. extern TVOID TMMUFree(TAPTR mmu, TAPTR mem)                                                __ELATE_QCALL__(("qcall lib/tek/mem/mmufree"));
  137. extern TUINT TMMUGetSize(TAPTR mmu, TAPTR mem)                                            __ELATE_QCALL__(("qcall lib/tek/mem/mmugetsize"));
  138.  
  139. /*#define TMMUAlloc(mmu, size)    (mmu) ? (*((TMMU *) (mmu))->allocfunc)(((TMMU *) (mmu))->allocator, (size)) : kn_alloc(size)*/
  140. /*#define TMMUFree(mmu, mem)    (mmu) ? (*((TMMU *) (mmu))->freefunc)(((TMMU *) (mmu))->allocator, (mem)) : kn_free(mem)*/
  141. /*#define TMMUGetSize(mmu, mem)    (mmu) ? (*((TMMU *) (mmu))->getsizefunc)(((TMMU *) (mmu))->allocator, (mem)) : kn_getsize(mem)*/
  142.  
  143. extern TAPTR TMMUAllocHandle(TAPTR mmu, TDESTROYFUNC destroyfunc, TUINT size)            __ELATE_QCALL__(("qcall lib/tek/mem/mmuallochandle"));
  144. extern TAPTR TMMUAllocHandle0(TAPTR mmu, TDESTROYFUNC destroyfunc, TUINT size)            __ELATE_QCALL__(("qcall lib/tek/mem/mmuallochandle0"));
  145. extern TVOID TMMUFreeHandle(TAPTR h)                                                    __ELATE_QCALL__(("qcall lib/tek/mem/mmufreehandle"));
  146.  
  147. extern TINT TDestroy(TAPTR object)                                                        __ELATE_QCALL__(("qcall lib/tek/mem/destroy"));
  148.  
  149.  
  150. TEND_C_API
  151.  
  152.  
  153. #endif
  154.